

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 参考资料 视频链接 运行环境  windows10 CentOS7虚拟机 JDK8 Hadoop3.1.3  一、Java MapReduce 编程规范 用于编写的程序分为三个部分：Mapper、Reducer和Driver 1.1 Mapper阶段 用户自定义的Mapper需继承自己的父类 Mapper的输入数据是KV对的形式（KV类型可自定义） Mapper中的业务逻辑卸载map">
<meta property="og:type" content="article">
<meta property="og:title" content="Hadoop _ MapReduce学习笔记（一）使用Java实现MapReduce编程 _ 打包词频统计程序为jar包提交到Hadoop集群并运行 _ Mapper、Reducer、Driver">
<meta property="og:url" content="http://example.com/2022/01/19/Hadoop%20_%20MapReduce%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%EF%BC%88%E4%B8%80%EF%BC%89%E4%BD%BF%E7%94%A8Java%E5%AE%9E%E7%8E%B0MapReduce%E7%BC%96%E7%A8%8B%20_%20%E6%89%93%E5%8C%85%E8%AF%8D%E9%A2%91%E7%BB%9F%E8%AE%A1%E7%A8%8B%E5%BA%8F%E4%B8%BAjar%E5%8C%85%E6%8F%90%E4%BA%A4%E5%88%B0Hadoop%E9%9B%86%E7%BE%A4%E5%B9%B6%E8%BF%90%E8%A1%8C%20_%20Mapper%E3%80%81Reducer%E3%80%81Driver/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 参考资料 视频链接 运行环境  windows10 CentOS7虚拟机 JDK8 Hadoop3.1.3  一、Java MapReduce 编程规范 用于编写的程序分为三个部分：Mapper、Reducer和Driver 1.1 Mapper阶段 用户自定义的Mapper需继承自己的父类 Mapper的输入数据是KV对的形式（KV类型可自定义） Mapper中的业务逻辑卸载map">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/6b2b95e3254a45d9aa9dea3185839a79.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/fb0a9e97d77640dc84e698cbc4b93fb8.gif#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/e3c8e02208f04c069fc9167454cc92d4.gif#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/b7a2774131c24513b5f5ae6b298b0f22.gif#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/1e1646631443491f99c695cbb66203e9.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/e57cf46c695a41668744d047365eb095.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/74566034dcb841fd81d564cc7db74305.png">
<meta property="article:published_time" content="2022-01-19T08:20:22.000Z">
<meta property="article:modified_time" content="2022-08-22T15:44:27.620Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="MapReduce">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/6b2b95e3254a45d9aa9dea3185839a79.png">
  
  
  
  <title>Hadoop _ MapReduce学习笔记（一）使用Java实现MapReduce编程 _ 打包词频统计程序为jar包提交到Hadoop集群并运行 _ Mapper、Reducer、Driver - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Hadoop _ MapReduce学习笔记（一）使用Java实现MapReduce编程 _ 打包词频统计程序为jar包提交到Hadoop集群并运行 _ Mapper、Reducer、Driver"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-01-19 16:20" pubdate>
          2022年1月19日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          7.8k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          65 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Hadoop _ MapReduce学习笔记（一）使用Java实现MapReduce编程 _ 打包词频统计程序为jar包提交到Hadoop集群并运行 _ Mapper、Reducer、Driver</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h1><hr>
<p><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1Qp4y1n7EN?p=71&spm_id_from=pageDriver">视频链接</a></p>
<h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><hr>
<ul>
<li>windows10</li>
<li>CentOS7虚拟机</li>
<li>JDK8</li>
<li>Hadoop3.1.3</li>
</ul>
<h1 id="一、Java-MapReduce-编程规范"><a href="#一、Java-MapReduce-编程规范" class="headerlink" title="一、Java MapReduce 编程规范"></a>一、Java MapReduce 编程规范</h1><hr>
<p>用于编写的程序分为三个部分：Mapper、Reducer和Driver</p>
<h2 id="1-1-Mapper阶段"><a href="#1-1-Mapper阶段" class="headerlink" title="1.1 Mapper阶段"></a>1.1 Mapper阶段</h2><ol>
<li>用户自定义的Mapper需继承自己的父类</li>
<li>Mapper的输入数据是KV对的形式（KV类型可自定义）</li>
<li>Mapper中的业务逻辑卸载map() 方法中</li>
<li>Maper的输出数据是KV对的形式（KV类型可自定义）</li>
<li>map()方法（MapTask进程）对每一个&lt;K,V&gt;调用一次</li>
</ol>
<h2 id="1-2-Reduce阶段"><a href="#1-2-Reduce阶段" class="headerlink" title="1.2 Reduce阶段"></a>1.2 Reduce阶段</h2><ol>
<li>用户自定义的Reducer要继承自己的父类</li>
<li>Reducer的输入数据类型赌赢Mapper的输出数据类型，也是KV、</li>
<li>Reducer的业务逻辑写在reduce()方法中</li>
<li>ReduceTask进程对<strong>每一组相同k</strong>的&lt;K, V&gt; 组调用一次reduce()方法</li>
</ol>
<h2 id="1-3-Driver阶段"><a href="#1-3-Driver阶段" class="headerlink" title="1.3 Driver阶段"></a>1.3 Driver阶段</h2><p>相当于YARN集群的客户端，用于提交我们整个程序到YARN集群，提交的是封装了MapReduce程序相关运行参数的Job对象。</p>
<h1 id="二、WordCount-案例"><a href="#二、WordCount-案例" class="headerlink" title="二、WordCount 案例"></a>二、WordCount 案例</h1><p>需求：在给定的文本文件中统计输出每一个单词出现的总次数</p>
<p>测试数据：</p>
<figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs applescript">hello wolrd<br>hello spark<br><span class="hljs-keyword">my</span> <span class="hljs-built_in">name</span> <span class="hljs-keyword">is</span> uni<br>hadoop <span class="hljs-keyword">is</span> nice<br>hadoop<br></code></pre></td></tr></table></figure>

<p>预期结果：</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs apache"><span class="hljs-attribute">hello</span> <span class="hljs-number">2</span><br><span class="hljs-attribute">hadoop</span> <span class="hljs-number">2</span><br><span class="hljs-attribute">is</span> <span class="hljs-number">2</span><br><span class="hljs-attribute">my</span> <span class="hljs-number">1</span><br><span class="hljs-attribute">name</span> <span class="hljs-number">1</span><br><span class="hljs-attribute">nice</span> <span class="hljs-number">1</span><br><span class="hljs-attribute">spark</span> <span class="hljs-number">1</span><br><span class="hljs-attribute">uni</span> <span class="hljs-number">1</span><br><span class="hljs-attribute">world</span> <span class="hljs-number">1</span><br></code></pre></td></tr></table></figure>

<h2 id="2-1-Mapper"><a href="#2-1-Mapper" class="headerlink" title="2.1 Mapper"></a>2.1 Mapper</h2><ol>
<li>将MapTask传给文本内容，先转换成String</li>
<li>根据空格将这一行切分成单词</li>
<li>将单词转化为&lt;单词, 1&gt; 的形式<br><code>WordCountMapper.java</code><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.mr.wordcount;<br><br><span class="hljs-keyword">import</span> org.apache.hadoop.io.IntWritable;<br><span class="hljs-keyword">import</span> org.apache.hadoop.io.LongWritable;<br><span class="hljs-keyword">import</span> org.apache.hadoop.io.Text;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.Mapper;<br><br><span class="hljs-keyword">import</span> java.io.IOException;<br><br><span class="hljs-comment">/** 词频统计</span><br><span class="hljs-comment"> * &lt;KEYIN, VALUEIN, KEYOUT, VALUEOUT&gt;</span><br><span class="hljs-comment"> * KEYIN , map 阶段输入key的类型: LongWritable</span><br><span class="hljs-comment"> * VALUEIN, map 阶段输入value的类型: Text</span><br><span class="hljs-comment"> * KEYOUT, map 阶段输出vkey的类型：Text</span><br><span class="hljs-comment"> * VALUEOUT, map阶段输出的value类型：IntWritable</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">WordCountMapper</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Mapper</span>&lt;LongWritable, Text, Text, IntWritable&gt; &#123;<br>    <span class="hljs-comment">// 放在上面声明防止在循环里多次创建对象，浪费空间</span><br>    <span class="hljs-keyword">private</span> <span class="hljs-type">Text</span> <span class="hljs-variable">outKey</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Text</span>();<br>    <span class="hljs-keyword">private</span> <span class="hljs-type">IntWritable</span> <span class="hljs-variable">outValue</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">IntWritable</span>(<span class="hljs-number">1</span>);<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">map</span><span class="hljs-params">(LongWritable key, Text value, Context context)</span> <span class="hljs-keyword">throws</span> IOException, InterruptedException &#123;<br>        <span class="hljs-comment">// 1. 获取一行</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">line</span> <span class="hljs-operator">=</span> value.toString();<br>        <span class="hljs-comment">// 2. 切割</span><br>        String[] words = line.split(<span class="hljs-string">&quot; &quot;</span>);<br>        <span class="hljs-comment">// 3. 循环写出</span><br>        <span class="hljs-keyword">for</span> (String word : words) &#123;<br>            <span class="hljs-comment">// 封装 outKey</span><br>            outKey.set(word);<br>            context.write(outKey, outValue);<br>        &#125;<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure></li>
</ol>
<h2 id="2-2-Reducer"><a href="#2-2-Reducer" class="headerlink" title="2.2 Reducer"></a>2.2 Reducer</h2><ol>
<li>汇总各个key的个数</li>
<li>输出该key的总次数</li>
</ol>
<p><code>WordCountReducer.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.mr.wordcount;<br><br><span class="hljs-keyword">import</span> org.apache.hadoop.io.IntWritable;<br><span class="hljs-keyword">import</span> org.apache.hadoop.io.Text;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.Reducer;<br><br><span class="hljs-keyword">import</span> java.io.IOException;<br><br><span class="hljs-comment">/** 词频统计</span><br><span class="hljs-comment"> * &lt;KEYIN, VALUEIN, KEYOUT, VALUEOUT&gt;</span><br><span class="hljs-comment"> * KEYIN , reduce 阶段输入key的类型: Text</span><br><span class="hljs-comment"> * VALUEIN, reduce 阶段输入value的类型: IntWritable</span><br><span class="hljs-comment"> * KEYOUT, reduce 阶段输出vkey的类型：Text</span><br><span class="hljs-comment"> * VALUEOUT, reduce阶段输出的value类型：IntWritable</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">WordCountReducer</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Reducer</span>&lt;Text, IntWritable, Text, IntWritable&gt; &#123;<br>    <span class="hljs-keyword">private</span>  <span class="hljs-type">IntWritable</span> <span class="hljs-variable">outValue</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">IntWritable</span>();<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">reduce</span><span class="hljs-params">(Text key, Iterable&lt;IntWritable&gt; values, Context context)</span> <span class="hljs-keyword">throws</span> IOException, InterruptedException &#123;<br>        <span class="hljs-type">int</span> <span class="hljs-variable">sum</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;<br>        <span class="hljs-comment">// 累加</span><br>        <span class="hljs-keyword">for</span> (IntWritable value : values) &#123;<br>            sum += value.get();<br>        &#125;<br>        outValue.set(sum);<br>        <span class="hljs-comment">// 写出</span><br>        context.write(key, outValue);<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<h2 id="2-3-Driver"><a href="#2-3-Driver" class="headerlink" title="2.3 Driver"></a>2.3 Driver</h2><p><code>WordCountDriver.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.mr.wordcount;<br><br><span class="hljs-keyword">import</span> org.apache.hadoop.conf.Configuration;<br><span class="hljs-keyword">import</span> org.apache.hadoop.fs.Path;<br><span class="hljs-keyword">import</span> org.apache.hadoop.io.IntWritable;<br><span class="hljs-keyword">import</span> org.apache.hadoop.io.Text;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.Job;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.lib.input.FileInputFormat;<br><br><span class="hljs-keyword">import</span> java.io.IOException;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">WordCountDriver</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException, InterruptedException, ClassNotFoundException &#123;<br>        <span class="hljs-comment">// 1. 获取 job</span><br>        <span class="hljs-type">Configuration</span> <span class="hljs-variable">conf</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Configuration</span>();<br>        <span class="hljs-type">Job</span> <span class="hljs-variable">job</span> <span class="hljs-operator">=</span> Job.getInstance(conf);<br>        <span class="hljs-comment">// 2. 设置jar包路径</span><br>        job.setJarByClass(WordCountDriver.class);<br>        <span class="hljs-comment">// 3. 关联 mapper 和 reducer</span><br>        job.setMapperClass(WordCountMapper.class);<br>        job.setReducerClass(WordCountReducer.class);<br>        <span class="hljs-comment">// 4. 设置 map 输出的 k v 类型</span><br>        job.setMapOutputKeyClass(Text.class);<br>        job.setMapOutputValueClass(IntWritable.class);<br>        <span class="hljs-comment">// 5. 设置最终输出的k v类型</span><br>        job.setOutputKeyClass(Text.class);<br>        job.setOutputValueClass(IntWritable.class);<br>        <span class="hljs-comment">// 6. 设置输入路径和输出路径</span><br>        FileInputFormat.setInputPaths(job, <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(<span class="hljs-string">&quot;testInput&quot;</span>));<br>        FileOutputFormat.setOutputPath(job, <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(<span class="hljs-string">&quot;testOutput&quot;</span>));<br>        <span class="hljs-comment">// 7. 提交 job</span><br>        <span class="hljs-type">boolean</span> <span class="hljs-variable">result</span> <span class="hljs-operator">=</span> job.waitForCompletion(<span class="hljs-literal">true</span>);<br>        System.exit(result ? <span class="hljs-number">0</span> : <span class="hljs-number">1</span>);<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>运行结果：</p>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/2ba90cf7e37e43a49d40215cb71cd329.png#">https://img-blog.csdnimg.cn/2ba90cf7e37e43a49d40215cb71cd329.png#</a> &#x3D;80%x)</p>
<h2 id="2-4-DeBug调试"><a href="#2-4-DeBug调试" class="headerlink" title="2.4 DeBug调试"></a>2.4 DeBug调试</h2><p>先把调试的断点打好<br><strong>Map阶段：</strong><br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/2ddf6d9bd9344603af3b4310cda4da1c.png#">https://img-blog.csdnimg.cn/2ddf6d9bd9344603af3b4310cda4da1c.png#</a> &#x3D;80%x)<br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/d5f317a86acf4546942c911f770fd411.png#">https://img-blog.csdnimg.cn/d5f317a86acf4546942c911f770fd411.png#</a> &#x3D;80%x)<br><strong>Reduce阶段</strong></p>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/f04e593252934d2caa5aa2241f2e56f6.png#">https://img-blog.csdnimg.cn/f04e593252934d2caa5aa2241f2e56f6.png#</a> &#x3D;80%x)<br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/a81a040e6e8443fcb53d3e46a80b0131.png#">https://img-blog.csdnimg.cn/a81a040e6e8443fcb53d3e46a80b0131.png#</a> &#x3D;80%x)</p>
<p>IDEA 调试的按钮说明：<br><img src="https://img-blog.csdnimg.cn/6b2b95e3254a45d9aa9dea3185839a79.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>调试进入Map阶段：<br><img src="https://img-blog.csdnimg.cn/fb0a9e97d77640dc84e698cbc4b93fb8.gif#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>在Mapper阶段执行run方法时通过while循环判断<code>context.nextKeyValue()</code>，最后释放资源<code>cleanup(context)</code>由<code>MapTask类</code>的方法关闭资源，为方便观察Reduce阶段，直接点击IDEA左侧的恢复程序按钮，这样就能直接跳到下一个Reducer类里打的断点。</p>
<p><img src="https://img-blog.csdnimg.cn/e3c8e02208f04c069fc9167454cc92d4.gif#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>进入Reduce阶段：<br><img src="https://img-blog.csdnimg.cn/b7a2774131c24513b5f5ae6b298b0f22.gif#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>和Map阶段一样，Reducer也是通过run方法来执行任务，但是它的while循环判断是通过<code>context.nextKey()</code>，Reducer关键源码如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">while</span> (context.nextKey()) &#123;<br>  reduce(context.getCurrentKey(), context.getValues(), context);<br>  <span class="hljs-comment">// If a back up store is used, reset it</span><br>  Iterator&lt;VALUEIN&gt; iter = context.getValues().iterator();<br>  <span class="hljs-keyword">if</span>(iter <span class="hljs-keyword">instanceof</span> ReduceContext.ValueIterator) &#123;<br>    ((ReduceContext.ValueIterator&lt;VALUEIN&gt;)iter).resetBackupStore();        <br>  &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>而 Mapper类的部分是这样的：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">while</span> (context.nextKeyValue()) &#123;<br>   map(context.getCurrentKey(), context.getCurrentValue(), context);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>通过这个可以观察到，Reduce阶段多了一个步骤，这个步骤将会在之后的总结里记录。</p>
<h1 id="三、MR打包提交到Hadoop集群"><a href="#三、MR打包提交到Hadoop集群" class="headerlink" title="三、MR打包提交到Hadoop集群"></a>三、MR打包提交到Hadoop集群</h1><p>打包前，先将WordCountDriver类进行修改，实现根据命令输入的参数来进行指定路径的词频统计，就跟之前运行官方示例的效果一样，修改后的内容：</p>
<p><code>WordCountDriver.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.mr.wordcount;<br><br><span class="hljs-keyword">import</span> org.apache.hadoop.conf.Configuration;<br><span class="hljs-keyword">import</span> org.apache.hadoop.fs.Path;<br><span class="hljs-keyword">import</span> org.apache.hadoop.io.IntWritable;<br><span class="hljs-keyword">import</span> org.apache.hadoop.io.Text;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.Job;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.lib.input.FileInputFormat;<br><br><span class="hljs-keyword">import</span> java.io.IOException;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">WordCountDriver</span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException, InterruptedException, ClassNotFoundException &#123;<br>        <span class="hljs-comment">// 判断输入的参数是否符合要求</span><br>        <span class="hljs-keyword">if</span>(args.length != <span class="hljs-number">2</span>) &#123;<br>            System.out.println(<span class="hljs-string">&quot;请输入两个参数: [词频统计的输入文件目录] [输出的文件目录]&quot;</span>);<br>            System.exit(<span class="hljs-number">1</span>);<br>        &#125;<br>        <span class="hljs-comment">// 1. 获取 job</span><br>        <span class="hljs-type">Configuration</span> <span class="hljs-variable">conf</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Configuration</span>();<br>        <span class="hljs-type">Job</span> <span class="hljs-variable">job</span> <span class="hljs-operator">=</span> Job.getInstance(conf);<br>        <span class="hljs-comment">// 2. 设置jar包路径</span><br>        job.setJarByClass(WordCountDriver.class);<br>        <span class="hljs-comment">// 3. 关联 mapper 和 reducer</span><br>        job.setMapperClass(WordCountMapper.class);<br>        job.setReducerClass(WordCountReducer.class);<br>        <span class="hljs-comment">// 4. 设置 map 输出的 k v 类型</span><br>        job.setMapOutputKeyClass(Text.class);<br>        job.setMapOutputValueClass(IntWritable.class);<br>        <span class="hljs-comment">// 5. 设置最终输出的k v类型</span><br>        job.setOutputKeyClass(Text.class);<br>        job.setOutputValueClass(IntWritable.class);<br>        <span class="hljs-comment">// 6. 设置输入路径和输出路径</span><br>        FileInputFormat.setInputPaths(job, <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(args[<span class="hljs-number">0</span>]));<br>        FileOutputFormat.setOutputPath(job, <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(args[<span class="hljs-number">1</span>]));<br>        <span class="hljs-comment">// 7. 提交 job</span><br>        <span class="hljs-type">boolean</span> <span class="hljs-variable">result</span> <span class="hljs-operator">=</span> job.waitForCompletion(<span class="hljs-literal">true</span>);<br>        System.exit(result ? <span class="hljs-number">0</span> : <span class="hljs-number">1</span>);<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>
<p>在使用Maven打包Jar程序时，若想要将项目的依赖一起打包在jar包中，就需先在pom.xml里导入相关的打包插件：（注：build标签必须放在dependency标签的后面）笔者在插件中制定了JDK版本，这里笔者用的是JDK8，若不相同记得修改。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">build</span>&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>maven-compiler-plugin<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span><br>                 <span class="hljs-tag">&lt;<span class="hljs-name">source</span>&gt;</span>1.8<span class="hljs-tag">&lt;/<span class="hljs-name">source</span>&gt;</span><br>                 <span class="hljs-tag">&lt;<span class="hljs-name">target</span>&gt;</span>1.8<span class="hljs-tag">&lt;/<span class="hljs-name">target</span>&gt;</span><br>             <span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span><br>         <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>maven-assembly-plugin<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span><br>                 <span class="hljs-tag">&lt;<span class="hljs-name">descriptorRefs</span>&gt;</span><br>                     <span class="hljs-tag">&lt;<span class="hljs-name">descriptorRef</span>&gt;</span>jar-with-dependencies<span class="hljs-tag">&lt;/<span class="hljs-name">descriptorRef</span>&gt;</span><br>                 <span class="hljs-tag">&lt;/<span class="hljs-name">descriptorRefs</span>&gt;</span><br>             <span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">executions</span>&gt;</span><br>                 <span class="hljs-tag">&lt;<span class="hljs-name">execution</span>&gt;</span><br>                     <span class="hljs-tag">&lt;<span class="hljs-name">id</span>&gt;</span>make-assembly<span class="hljs-tag">&lt;/<span class="hljs-name">id</span>&gt;</span><br>                     <span class="hljs-tag">&lt;<span class="hljs-name">phase</span>&gt;</span>package<span class="hljs-tag">&lt;/<span class="hljs-name">phase</span>&gt;</span><br>                     <span class="hljs-tag">&lt;<span class="hljs-name">goals</span>&gt;</span><br>                         <span class="hljs-tag">&lt;<span class="hljs-name">goal</span>&gt;</span>single<span class="hljs-tag">&lt;/<span class="hljs-name">goal</span>&gt;</span><br>                     <span class="hljs-tag">&lt;/<span class="hljs-name">goals</span>&gt;</span><br>                 <span class="hljs-tag">&lt;/<span class="hljs-name">execution</span>&gt;</span><br>             <span class="hljs-tag">&lt;/<span class="hljs-name">executions</span>&gt;</span><br>         <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span><br>     <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span><br> <span class="hljs-tag">&lt;/<span class="hljs-name">build</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p><strong>Maven 打包</strong></p>
<p><img src="https://img-blog.csdnimg.cn/1e1646631443491f99c695cbb66203e9.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>由于是上传到集群，本身具有MR运行的jar包，所以就将不带依赖的jar包上传到集群的节点中。</p>
<p><strong>注：</strong> 上传到集群后，Hadoop是采用集群的配置，路径地址就变成了HDFS的地址，而不是之前在windows的IDEA里调试的本地地址，所以需要在集群节点里创建测试的文本，上传到HDFS（步骤略）。</p>
<p>上传后好文件后执行jar包，执行前记得先开启<code>hdfs</code>和<code>yarn</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">hadoop jar HDFSLearn-1.0-SNAPSHOT.jar com.uni.mr.wordcount.WordCountDriver /input /output<br></code></pre></td></tr></table></figure>

<p>查看运行结果：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">hadoop fs -cat /output/*<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/e57cf46c695a41668744d047365eb095.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>可以看到和IDEA里运行的结果一样 ，但是否确认就是刚才的jar包起的作用呢？现故意少输入一个参数，看看有没有提示：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">hadoop jar HDFSLearn-1.0-SNAPSHOT.jar com.uni.mr.wordcount.WordCountDriver /input<br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/74566034dcb841fd81d564cc7db74305.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>可以看到，结果和程序里写的提示信息是一样的。</p>
<p>至此，MapReduce本地编程，提交到集群的运行测试已完毕。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/" class="category-chain-item">大数据</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/MapReduce/">#MapReduce</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Hadoop _ MapReduce学习笔记（一）使用Java实现MapReduce编程 _ 打包词频统计程序为jar包提交到Hadoop集群并运行 _ Mapper、Reducer、Driver</div>
      <div>http://example.com/2022/01/19/Hadoop _ MapReduce学习笔记（一）使用Java实现MapReduce编程 _ 打包词频统计程序为jar包提交到Hadoop集群并运行 _ Mapper、Reducer、Driver/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年1月19日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/01/20/Spring%20%E7%AC%94%E8%AE%B02%20%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5%E7%9A%84%E5%A4%9A%E7%A7%8D%E6%96%B9%E5%BC%8F%E6%9E%84%E9%80%A0%E6%B3%A8%E5%85%A5%E3%80%81p%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4%E6%B3%A8%E5%85%A5%E7%AD%89%20_%20AOP%E5%A4%9A%E7%A7%8D%E5%A2%9E%E5%BC%BA%E7%B1%BB%E5%9E%8B%E5%BC%82%E5%B8%B8%E6%8A%9B%E5%87%BA%E5%A2%9E%E5%BC%BA%E3%80%81%E7%8E%AF%E7%BB%95%E5%A2%9E%E5%BC%BA%E7%AD%89%20_%20%E6%B3%A8%E8%A7%A3%E5%BC%80%E5%8F%91%E5%AE%9E%E7%8E%B0%20IoC_DI%20%E5%92%8C%20AOP/" title="Spring 笔记2 依赖注入的多种方式构造注入、p命名空间注入等 _ AOP多种增强类型异常抛出增强、环绕增强等 _ 注解开发实现 IoC_DI 和 AOP">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Spring 笔记2 依赖注入的多种方式构造注入、p命名空间注入等 _ AOP多种增强类型异常抛出增强、环绕增强等 _ 注解开发实现 IoC_DI 和 AOP</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/01/19/Hadoop%20_%20%E9%9B%86%E7%BE%A4%E9%85%8D%E7%BD%AE%EF%BC%88%E4%B8%89%EF%BC%89%E5%AE%8C%E5%85%A8%E5%88%86%E5%B8%83%E5%BC%8F%E9%9B%86%E7%BE%A4%E8%A7%84%E5%88%92%20_%20%E9%85%8D%E7%BD%AE%E8%AF%A6%E6%83%85/" title="Hadoop _ 集群配置（三）完全分布式集群规划 _ 配置详情">
                        <span class="hidden-mobile">Hadoop _ 集群配置（三）完全分布式集群规划 _ 配置详情</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
